/*    

    bobbietalk - a visual programming environment for toy robotics

    Copyright (C) 2013  Roberto Tiella

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
package bobbietalk.gui.blocks.ifblk.open;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import bobbietalk.Utilities;
import bobbietalk.gui.blocks.ConditionBlock;
import static bobbietalk.gui.blocks.ifblk.open.IfOpenBlock.moveRelative;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

/**
 *
 * @author tiella
 */
public class IfOpenFalseBlock extends IfOpenLeftBlock /* implements IfGroup */ {

    public IfOpenFalseBlock() {

        try {
            BufferedImage icon = ImageIO.read(getClass().getResourceAsStream("/icons/not_ok_icon.png"));
            setIcon(new ImageIcon(icon));
        } catch (IOException ex) {
            Utilities.getLogger().log(Level.SEVERE, null, ex);
        }

        setBackground(new Color(0xF0A843));

        setText(Utilities.getTextBundle().getString("menu.item.add.if.false"));

    }

//    @Override
//    public void updatePosition(Rectangle r) {
//        
//        Rectangle b = getBounds();
//        
//        if (b.x != r.x || b.y != r.y) {
//            
//            IfBlock.updateBounds(getEntryBlock(),b.x,r.x,b.y,r.y);
//            IfBlock.updateBounds(getEntryBlock().getIfTrueBlock(),b.x,r.x,b.y,r.y);
//            
//            setRPosition(r.x, r.y);
//        }
//        
//        
//    }
    @Override
    public void setPosition(int x, int y) {

        Rectangle r = getBounds();

        setRPosition(x, y);

        getIfEntryBlock().setRDeltaPosition(r.x, x, r.y, y);
        getIfEntryBlock().getIfTrueBlock().setRDeltaPosition(r.x, x, r.y, y);


    }

    @Override
    public void propagateMotion(boolean moveYourself, int dx, int dy) {

        if (moveYourself) {
            moveRelative(this, 0, dx, 0, dy);
        }

        // getEntryBlock().getIfTrueBlock().propagateMotion(false, dx,dy);

        propagateRMotion(dx, dy);
        getIfEntryBlock().getIfTrueBlock().propagateRMotion(dx, dy);

    }
}
